<?php
/**
 * Created by PhpStorm.
 * User: zcq
 * Date: 2018/10/24
 * Time: 15:34
 */

namespace app\index\model;


use app\common\RedisCache;

class VoteWhite extends BaseModel
{
    public static function getWhite($voteId,$mobile='')
    {
        $key = 'vote_white_'.$voteId;
        $expireTime = 30*24*3600;
        $whites = RedisCache::getInstance()->cache($key);
        if($whites !== false){
            $whites = json_decode($whites,1);
        }else{
            $whites = self::where('vote_id',$voteId)->select();
            RedisCache::getInstance()->cache($key,json_encode($whites,JSON_UNESCAPED_UNICODE),$expireTime);
        }
        //查找活动的全部白名单
        if(!$mobile)
            return $whites;

        if($whites){
            foreach ($whites as $v){
                if($v['mobile'] == $mobile){
                    return $v;
                }
            }
        }
        return null;
    }
}